package com.cxc.minio.common.pojo;


import com.cxc.minio.common.constant.CodeEnums;
import lombok.Data;

import java.io.Serializable;

@Data
public class CommonResult implements Serializable {


    private String code;
    /**
     * 返回数据
     */
    private Object data;
    /**
     * 错误提示，用户可阅读
     */
    private String msg;

    public CommonResult(Object data, CodeEnums codeEnums) {
        this.data = data;
        this.code = codeEnums.getCode();
        this.msg = codeEnums.getMsg();
    }

    public CommonResult(Object data, String code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public static CommonResult success() {
        return new CommonResult((Object)null, CodeEnums.SUCCESS_CODE);
    }

    public static CommonResult success(Object data) {
        return new CommonResult(data, CodeEnums.SUCCESS_CODE);
    }



    public static CommonResult error() {
        return new CommonResult((Object)null, CodeEnums.ERROR_CODE);
    }

    public static CommonResult error(Object data) {
        return new CommonResult(data, CodeEnums.ERROR_CODE);
    }



    public static CommonResult msg(String msg) {
        return new CommonResult((Object)null, CodeEnums.ERROR_MSG.getCode(), msg);
    }

    public static CommonResult notLogin() {
        return new CommonResult((Object)null, CodeEnums.NOT_LOGIN);
    }

    public static CommonResult noResult() {
        return new CommonResult((Object)null, CodeEnums.NO_RESULT);
    }

    public static CommonResult build(Object data, String code, String msg) {
        return new CommonResult(data, code, msg);
    }

    public static CommonResult build(Object data, CodeEnums codeEnums) {
        return new CommonResult(data, codeEnums.getCode(), codeEnums.getMsg());
    }

    public static CommonResult build(CodeEnums codeEnums) {
        return new CommonResult(null, codeEnums.getCode(), codeEnums.getMsg());
    }

    public static CommonResult build(String code, String msg) {
        return new CommonResult(null, code, msg);
    }







}
